package ua.com.minus1.lookbattle.utils;

import android.content.Context;
import android.content.SharedPreferences;
import ua.com.minus1.lookbattle.models.Country;

/**
 * Created with IntelliJ IDEA.
 * User: Flash
 * Date: 20.07.12
 * Time: 15:36
 * To change this template use File | Settings | File Templates.
 */
public class AppPreferences {

    private static final String SHARED_PREFS = "ua.com.minus1.lookbattle.shprefs";
    private SharedPreferences sharedPrefs;
    private SharedPreferences.Editor prefsEditor;

    public AppPreferences(Context context) {
        sharedPrefs = context.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE);
        prefsEditor = sharedPrefs.edit();
    }

    public String getUUID() {
        return sharedPrefs.getString("uuid", "");
    }

    public void setUUID(String uuid) {
        prefsEditor.putString("uuid", uuid);
        prefsEditor.commit();
    }

    public boolean getRegistered() {
        return sharedPrefs.getBoolean("registered", false);
    }

    public void setRegistered(Boolean registered) {
        prefsEditor.putBoolean("registered", registered);
        prefsEditor.commit();
    }

    public void setClicks(int clicks) {
        prefsEditor.putInt("clicks", clicks);
        prefsEditor.commit();
    }

    public int getClicks() {
        return sharedPrefs.getInt("clicks", 0);
    }

    public void setCountry(Country country) {
        prefsEditor.putString("countryName", country.name);
        prefsEditor.putInt("countryId", country.id);
        prefsEditor.commit();
    }

    public Country getCountry() {
        Country country = new Country();
        country.id = sharedPrefs.getInt("countryId", -1);
        if(country.id != -1) {
            country.name = sharedPrefs.getString("countryName", "");
            return country;
        };
        return null;
    }
}
